from PyQt4.QtGui import QWidget
from PyQt4 import QtCore,QtGui
import pyqtgraph as pg
from KModel.KSingleStock import KSingleStock
class KChartAxisItem(pg.AxisItem):
	def Initialize(self,stockobject):
	# initialize with the stock object
		self.m_stock=stockobject
		#self.UpdateDisplay()
	def UpdateDisplay(self):
		pass
		'''
		           [
                [ (majorTickValue1, majorTickString1), (majorTickValue2, majorTickString2), ... ],
                [ (minorTickValue1, minorTickString1), (minorTickValue2, minorTickString2), ... ],
                ...
            ]
		'''
		TickNum=10
		ticklist=[[],[]]
		mindexlist=self.m_stock.CurWindowData('Index')
		datelist=self.m_stock.CurWindowData('Time')
		offset=int(round(len(mindexlist)/TickNum))
		for index in range(0,len(mindexlist),offset):
			ticklist[0].append((mindexlist[index],str(datelist[index])))
		self.setTicks(ticklist)
		self.update(self.boundingRect()) # update this item
		self.informViewBoundsChanged() # inform its viewbox to update,otherwise the viewbox related can't update(like axis)		
		
	def tickStrings(self, values, scale, spacing):
		
		"""Return values describing the desired spacing and offset of ticks.
		
		This method is called whenever the axis needs to be redrawn and is a 
		good method to override in subclasses that require control over tick locations.
		
		The return value must be a list of three tuples::
		
			[
				(major tick spacing, offset),
				(minor tick spacing, offset),
				(sub-minor tick spacing, offset),
				...
			]
		"""
		strns=[]
		if not hasattr(self,'m_stock'):
			return []
		labelarr=self.m_stock.GetDatesByIndex(values)
		strns.extend(labelarr)
		return strns
